/**
 * 
 */
package com.tport.server.controller;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tport.LogUtil;
import com.tport.server.service.PortServerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;


/**
 * @author stronghill
 *
 */
@Controller
@Api(tags = {"tport"})
public class PortServerController {
	private static ServerSocket ss = null;//new ServerSocket(8888);

	@Autowired
	private PortServerService portServerService;
	
	private static Map<String , List<Socket>> cmap = new HashMap<String, List<Socket>>();
	public static synchronized int  open() {
		com.tport.LogUtil.getAppDebugLog().debug("PortServerController.open");
		try {
			ss = new ServerSocket(8888);
			Socket c = null;
			c = ss.accept();
			while( null != c) {
//				c.rea
				c = ss.accept();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/", method = {RequestMethod.POST,RequestMethod.GET})
	@ApiOperation(httpMethod = "POST,GET", value = "保存草稿", notes = "保存草稿")//swagger 当前接口注解
	@ApiImplicitParams({
		  @ApiImplicitParam(name="idBusinessType",value="业务类型",dataType="string",required=true, paramType = "query",example="PROJECT_DAILY_REPORT")
		  ,@ApiImplicitParam(name="idFileBusiness",value="草稿id，附件业务id",dataType="string",required=true, paramType = "query",example="101010100")})
	//swagger返回值注解
	@ApiResponses(value = {
		@ApiResponse(code = 500, message = "系统错误"),
	        @ApiResponse(code = 200, message = "成功,返回格式：{code:1,msg:'',data[{}]},data中的属性参照下方Model", response = void.class) })
	public ModelAndView au01(HttpServletRequest request, HttpServletResponse response) {
		com.tport.LogUtil.getAppDebugLog().debug("PortServerController.au01.request=" + request.getQueryString() + ",contextPath=" + request.getContextPath());
		System.out.println(request.getContextPath());
		Map mapStr=new HashMap();
		String errorStr="";
        String contextIpPort = (String)request.getSession().getAttribute("contextIpPort");
		try{
		    String values=request.getParameter("values");
    	}catch(Exception e){
    		com.tport.LogUtil.getAppDebugLog().error("PortServerController.au01", e);
    		try {
	    		response.setHeader("Content-Type", "text/html");
				response.getWriter().write(	"{\"success\":\"false\",\"data\":\""+errorStr+"\"}");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
    		
    	}
		return null;
	}

}
